/**
 * 
 */
(function($){
	
	var appli_grid= "#appli-grid";
	var appli_pager="#appli-pager";

	var repair_grid="#repair-grid";
	var repair_pager="#repair-pager"
		
	var parent_column1 = $(appli_grid).closest('[class*="col-"]');
	var parent_column2 = $(repair_grid).closest('[class*="col-"]');
	
	//根据父col的宽度定义gird的宽度
	$(window).on('resize.jqGrid',function(){
		$(appli_grid).jqGrid('setGridWidth',parent_column1.width());
		$(repair_grid).jqGrid('setGridWidth',parent_column2.width());
	});
	
	//根据sidebar的变化调整
	$(document).on('settings.ace.jqGrid',function(ev,event_name,collapsed){
		if(event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed'){
			setTimeout(function(){
				$(appli_grid).jqGrid('setGridWidth',parent_column1.width());
				$(repair_grid).jqGrid('setGridWidth',parent_column2.width());
			},0);
		}
	})
	
	$(appli_grid).jqGrid({
		url:"loadRepairApply",
		datatype: "json",
		height:358,
		hiddengrid:true,
		colNames:['id','维修单号','维修单状态','设备编号', '设备名称','设备ID','申请人','报修时间','关键字'],
		colModel:[
					{name:'id',index:'id',editable:true,hidden:true},
					{name:'repairNo',index:'repairNo',editable: true,search:false},
					{name:'state',index:'state',editable: false,search:false},
					{name:'deviceCode',index:'deviceCode',editable: false,search:false},
					{name:'deviceName',index:'deviceName',editable: false,search:false},
					{name:'od_id',index:'od_id',editable: true,search:false,edittype:"select",editoptions:{value:getDevice()}},
					{name:'applyMan',index:'applyMan',editable:false,search:false},
					{name:'createTime',index:'createTime',editable:false,search:false},
					{name:'keywords',index:'keywords',hidden:true,search:true,searchoptions:{searchhidden:true,sopt:['eq']}}
					
				],
				viewrecords:true,
				rowNum:10,
				rowList:[10,20,30],
				pager:appli_pager,
				altRows:true,
				multiselect:true,
				multiboxonly:true,
				loadComplete:function(){
					var table=this;
					setTimeout(function(){
//							styleCheckbox(table);
//							updateActionIcons(table);
							updatePagerIcons(table);
//							enableTooltips(table);
					},0);
				},
				editurl: "operRepairApply",//nothing is savedw
				caption: "维修申请"
	});
	$(repair_grid).jqGrid({
		url:"loadRepairRecord",
		datatype: "json",
		height:358,
		hiddengrid:true,
		colNames:['id','维修单号','维修单状态','设备编号', '设备名称','设备ID','申请人','报修时间','维修开始时间','维修完成时间','停机时间（小时）','维修级别','维修人员','维修责任人','维修费用','故障描述','工作描述','关键字'],
		colModel:[
					{name:'id',index:'id',editable:true,hidden:true},
					{name:'repairNo',index:'repairNo',editable: true,search:false},
					{name:'state',index:'state',editable: false,search:false},
					{name:'deviceCode',index:'deviceCode',editable: false,search:false},
					{name:'deviceName',index:'deviceName',editable: false,search:false},
					{name:'od_id',index:'od_id',editable: true,search:false,edittype:"select",editoptions:{value:getDevice()}},
					{name:'applyMan',index:'applyMan',editable:false,search:false},
					{name:'createTime',index:'createTime',editable:false,search:false},
					{name:'startTime',index:'startTime',editable:false,search:false},
					{name:'endTime',index:'endTime',editable:false,search:false},
					{name:'stopTime',index:'stopTime',editable:true,search:false},
					{name:'level',index:'level',editable:true,edittype:"select",editoptions:{value:"1:例行检修;2:配件更换;3:部件维修;4:小修;5:大修"},search:false},
					{name:'repairMan',index:'repairMan',editable:false,search:false},
					{name:'responsibleMan',index:'responsibleMan',editable:false,search:false},
					{name:'fee',index:'fee',editable:true,search:false},
					{name:'detail',index:'detail',search:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"20"}},
					{name:'workDetail',index:'workDetail',search:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"20"}},
					{name:'keywords',index:'keywords',hidden:true,search:true,searchoptions:{searchhidden:true,sopt:['eq']}}
					],
				viewrecords:true,
				rowNum:10,
				rowList:[10,20,30],
				pager:repair_pager,
				altRows:true,
				multiselect:true,
				multiboxonly:true,
				loadComplete:function(){
					var table=this;
					setTimeout(function(){
//							styleCheckbox(table);
//							updateActionIcons(table);
							updatePagerIcons(table);
//							enableTooltips(table);
					},0);
				},
				editurl: "operRepairRecord",//nothing is savedw
				caption: "维修记录"
	});
	
	$(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size
	
/*	function aceSwitch( cellvalue, options, cell ) {
		setTimeout(function(){
			$(cell) .find('input[type=checkbox]')
				.addClass('ace ace-switch ace-switch-5')
				.after('<span class="lbl"></span>');
		}, 0);
	}*/
	function getDevice(){
		var str="";
		$.ajax({
			type:"post",
			async:false,
			url:"checkOperationDevice",
			success:function(data){
				for(var i=0;i<data.length;i++){
					if(i!=data.length-1){
						str+=data[i].id+":"+data[i].deviceName+";";
					}else{
						str+=data[i].id+":"+data[i].deviceName;
					}
				}
			}
		});
		return str;
	}
	//enable datepicker
	function pickDate( cellvalue, options, cell ) {
		setTimeout(function(){
			$(cell) .find('input[type=text]')
					.datepicker({format:'yyyy-mm-dd HH:MM:ss' , autoclose:true}); 
		}, 0);
	}
	
	jQuery(appli_grid).jqGrid('navGrid',appli_pager,
			{ 	//navbar options
				edit: false,
				editicon : 'ace-icon fa fa-pencil blue',
				add: true,
				addicon : 'ace-icon fa fa-plus-circle purple',
				del: true,
				delicon : 'ace-icon fa fa-trash-o red',
				search: true,
				searchicon : 'ace-icon fa fa-search orange',
				refresh: true,
				refreshicon : 'ace-icon fa fa-refresh green',
				view: true,
				viewicon : 'ace-icon fa fa-search-plus grey',
			},
			{
				//edit record form
				drag:false,
				closeAfterEdit:true,
				recreateForm: true,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
					style_edit_form(form);
					enabledrag(form);
				}
			},
			{
				//new record form
				drag:false,
				closeAfterAdd: true,
				recreateForm: true,
				viewPagerButtons: false,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
					style_edit_form(form);
					enabledrag(form);
				}
			},
			{
				//delete record form
				drag:false,
				recreateForm: true,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					if(form.data('styled')) return false;
					enabledrag(form);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
					style_delete_form(form);
					
					form.data('styled', true);
				},
				onClick : function(e) {
					//alert(1);
				}
			},
			{
				//search form
				drag:false,
				recreateForm: true,
				afterShowSearch: function(e){
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
					style_search_form(form);
					enabledrag(form);
				},
				afterRedraw: function(){
					style_search_filters($(this));
				}
				,
				multipleSearch: false
				/**
				multipleGroup:true,
				showQuery: true
				*/
			},
			{
				//view record form
				drag:false,
				recreateForm: true,
				beforeShowForm: function(e){
					var form = $(e[0]);
					enabledrag(form);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
				}
			}
		).navButtonAdd(appli_pager,{
			caption:"",
			title:"执行",
			buttonicon:"ui-icon ace-icon fa fa-check",
	/*		onClickButton:function(){
				var id=$(plan_grid).getGridParam('selrow');
//				$(plan_grid).setSelection(id, true);
				$(plan_grid).setRowData(id,{states:"待确认"});
			},*/
			/*beforeShowForm:function(){
				$("#dialog-appli").closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />');
			},*/
			onClickButton:function(){
				if($("#dialog-appli")){
					$("#dialog-appli").remove();
				}
	            $("body").append('<div class="hide" id="dialog-appli"></div>');
	            var divwrap=$("#dialog-appli");
	                $("#dialog-appli").append('<div class="widget-body appli-body"></div>');
	                    $(".appli-body").append('<div class="widget-main no-padding appli-main"></div>');
	                    $(".appli-main").append('<div><label class="col-xs-4">维修级别</label>\
							                    		<select id="level" class="col-xs-8">\
								                    		<option value=1 slected>例行检修</option>\
								                    		<option value=2>配件更换</option>\
								                    		<option value=3>部件维修</option>\
		                    								<option value=4>小修</option>\
		                    								<option value=5>大修</option>\
	                    								</select></div>');
	                    $(".appli-main").append('<div><label class="col-xs-4">维修人员</label><input type="text" id="repairMan" class="col-xs-8"></div>');
	                    $(".appli-main").append('<div><label class="col-xs-4">故障描述</label><textarea id="detail" class="col-xs-8"></textarea></div>');
                    $( "#dialog-appli" ).removeClass('hide').dialog({
					resizable: false,
//					width: '320',
					modal: true,
//					title_html: true,
//					title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>zhi'i</h4></div>",
					title: "执行",
					buttons: [
						{
							html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; 执行",
							"class" : "btn btn-danger btn-minier",
							click: function() {
//								$( this ).dialog( "close" );
								var id=$(appli_grid).getGridParam('selrow');
//								$(appli_grid).setRowData(id,{state:"已确认"});
								$( this ).dialog( "close" );
								$.ajax({
									type:"get",
									url:"operRepairApply",
									data:{state:"2",oper:"edit",id:id,startTime:new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,''),level:$("#level").val(),repairMan:$("#repairMan").val(),detail:$("#detail").val()},
									success:function(){
										/*$(appli_grid).jqGrid('setGridParam',{
											
										}).trigger('reloadGrid');*/
										$(appli_grid).trigger('reloadGrid');
										$(repair_grid).trigger('reloadGrid');
									},
									error:function(){
										alert(arguments[1]);
									}
								})
							}
						}
						,
						{
							html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 取消",
							"class" : "btn btn-minier",
							click: function() {
//								$("#dialog-confirm").addClass('hide');
								$( this ).dialog( "close" );
							}
						}
					]
				});        
			},
			position:"first"
		});
		
		jQuery(repair_grid).jqGrid('navGrid',repair_pager,
			{ 	//navbar options
				edit: true,
				editicon : 'ace-icon fa fa-pencil blue',
				add: false,
				addicon : 'ace-icon fa fa-plus-circle purple',
				del: true,
				delicon : 'ace-icon fa fa-trash-o red',
				search: true,
				searchicon : 'ace-icon fa fa-search orange',
				refresh: true,
				refreshicon : 'ace-icon fa fa-refresh green',
				view: true,
				viewicon : 'ace-icon fa fa-search-plus grey',
			},
			{
				//edit record form
				drag:false,
				closeAfterEdit:true,
				recreateForm: true,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
					style_edit_form(form);
					enabledrag(form);
				}
			},
			{
				//new record form
				drag:false,
				closeAfterAdd: true,
				recreateForm: true,
				viewPagerButtons: false,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')
					.wrapInner('<div class="widget-header" />')
					style_edit_form(form);
					enabledrag(form);
				}
			},
			{
				//delete record form
				drag:false,
				recreateForm: true,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					if(form.data('styled')) return false;
					
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
					style_delete_form(form);
					enabledrag(form);
					form.data('styled', true);
				},
				onClick : function(e) {
					//alert(1);
				}
			},
			{
				//search form
				drag:false,
				recreateForm: true,
				afterShowSearch: function(e){
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
					style_search_form(form);
					enabledrag(form);
				},
				afterRedraw: function(){
					style_search_filters($(this));
				}
				,
				multipleSearch: false,
				/**
				multipleGroup:true,
				showQuery: true
				*/
			},
			{
				//view record form
				drag:false,
				recreateForm: true,
				beforeShowForm: function(e){
					var form = $(e[0]);
					enabledrag(form);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
				}
			}
		).navButtonAdd(repair_pager,{
			caption:"",
			title:"完成",
//			buttonicon:"ui-icon ace-icon fa fa-pencil purple",
			buttonicon:"ui-icon ace-icon fa fa-check",
	/*		onClickButton:function(){
				var id=$(plan_grid).getGridParam('selrow');
//				$(plan_grid).setSelection(id, true);
				$(plan_grid).setRowData(id,{states:"待确认"});
			},*/
			onClickButton:function(){
				if($("#dialog-repair")){
					$("#dialog-repair").remove();
				}
	            $("body").append('<div class="hide" id="dialog-repair"></div>');
	            var divwrap=$("#dialog-repair");
	                $("#dialog-repair").append('<div class="widget-body repair-body"></div>');
	                    $(".repair-body").append('<div class="widget-main no-padding repair-main"></div>');
	                    $(".repair-main").append('<div><label class="col-xs-6">维修级别</label>\
							                    		<select id="state" class="col-xs-6">\
		                    								<option value=4>无法修复</option>\
		                    								<option value=5>已完成</option>\
	                    								</select></div>');
	                    $(".repair-main").append('<div><label class="col-xs-6">维修责任人</label><input type="text" id="responsibleMan" class="col-xs-6"></div>');
	                    $(".repair-main").append('<div><label class="col-xs-6">维修费用</label><input type="text" id="fee" class="col-xs-6"></div>');
	                    $(".repair-main").append('<div><label class="col-xs-6">故障描述</label><textarea id="workDetail" class="col-xs-6"></textarea></div>');/*function(id){
				var divwrap = document.createElement('div');
			    divwrap.innerHTML ='<div id="dialog-repair" class="hide" style="height:400px;"><div><label>维修单状态</label><select id="State"><option value=4>无法修复&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option><option value=5>已完成</option></select><br/></div><div style="margin-top:10px;"><label>维修责任人</label><input type="text" id="ResponsibleMan"></div><div style="margin-top:10px"><label>维修费用</label><input type="text" id="Fee"></div><div style="margin-top:10px"><label>工作描述</label><textarea id="WorkDetail"></textarea></div></div>';
			    document.body.appendChild(divwrap);
			    var W=divwrap.firstChild.offsetWidth;
			    var H=divwrap.firstChild.offsetHeight;
			    var L=(document.documentElement.clientWidth-W)/2;
			    var T=(document.documentElement.clientHeight-H)/2;
			    divwrap.style.position="absolute";
			    divwrap.style.left=L+"px";
			    divwrap.style.top=T+"px";*/
			    
			    
			    $( "#dialog-repair" ).removeClass('hide').dialog({
					resizable: false,
//					width: '320',
					modal: true,
//					title_html: true,
//					title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i> Empty the recycle bin?</h4></div>",
					title: "完成",
					buttons: [
						{
							html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; 完成",
							"class" : "btn btn-danger btn-minier",
							click: function() {
//								$( this ).dialog( "close" );
								var id=$(repair_grid).getGridParam('selrow');
//								$(repair_grid).setRowData(id,{state:"已确认"});
								var startTime=$(repair_grid).jqGrid("getRowData",id).startTime;
								$( this ).dialog( "close" );
								$.ajax({
									type:"get",
									url:"operRepairRecord",
									data:{state:$("#state").val(),oper:"editState",id:id,endTime:new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,''),startTime:startTime,responsibleMan:$("#responsibleMan").val(),fee:$("#fee").val(),workDetail:$("#workDetail").val()},
									success:function(){
										/*$(appli_grid).jqGrid('setGridParam',{
											
										}).trigger('reloadGrid');*/
//										$(appli_grid).trigger('reloadGrid');
										$(repair_grid).trigger('reloadGrid');
									},
									error:function(){
										alert(arguments[1]);
									}
								})
							}
						}
						,
						{
							html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 取消",
							"class" : "btn btn-minier",
							click: function() {
//								$("#dialog-confirm").addClass('hide');
								$( this ).dialog( "close" );
							}
						}
					]
				});
			},
			position:"first"
		});
		function style_edit_form(form) {
			form.find('input[name=applyTime]').datepicker({format:'yyyy-mm-dd' , autoclose:true});
			form.find('input[name=startTime]').datepicker({format:'yyyy-mm-dd' , autoclose:true});
			form.find('input[name=endTime]').datepicker({format:'yyyy-mm-dd' , autoclose:true});
			
    						//enable datepicker on "sdate" field and switches for "stock" field
//    						form.find('input[name=applicationTime]').datepicker({format:'yyyy-mm-dd' , autoclose:true});
//    						form.find('input[name=startTime]').datepicker({format:'yyyy-mm-dd' , autoclose:true});
//    						form.find('input[name=finishTime]').datepicker({format:'yyyy-mm-dd' , autoclose:true});
//    								   //don't wrap inside a label element, the checkbox value won't be submitted (POST'ed)
    								  //.addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');
    				
    								
    						//update buttons classes
//    						var buttons = form.next().find('.EditButton .fm-button');
//    						buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide();//ui-icon, s-icon
//    						buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
//    						buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>')
//    						
//    						buttons = form.next().find('.navButton a');
//    						buttons.find('.ui-icon').hide();
//    						buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
//    						buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');		
	}
	function style_delete_form(form) {
		var buttons = form.next().find('.EditButton .fm-button');
		buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide();//ui-icon, s-icon
		buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
		buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
	}
	
	function style_search_filters(form) {
		form.find('.delete-rule').val('X');
		form.find('.add-rule').addClass('btn btn-xs btn-primary');
		form.find('.add-group').addClass('btn btn-xs btn-success');
		form.find('.delete-group').addClass('btn btn-xs btn-danger');
	}
	function style_search_form(form) {
		var dialog = form.closest('.ui-jqdialog');
		var buttons = dialog.find('.EditTable')
		buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
		buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
		buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
	}
	
	function beforeDeleteCallback(e) {
		var form = $(e[0]);
		if(form.data('styled')) return false;
		
		form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
		style_delete_form(form);
		
		form.data('styled', true);
	}
	
	function beforeEditCallback(e) {
		var form = $(e[0]);
		form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
		style_edit_form(form);
	}



	//it causes some flicker when reloading or navigating grid
	//it may be possible to have some custom formatter to do this as the grid is being created to prevent this
	//or go back to default browser checkbox styles for the grid
	function styleCheckbox(table) {
	/**
		$(table).find('input:checkbox').addClass('ace')
		.wrap('<label />')
		.after('<span class="lbl align-top" />')


		$('.ui-jqgrid-labels th[id*="_cb"]:first-child')
		.find('input.cbox[type=checkbox]').addClass('ace')
		.wrap('<label />').after('<span class="lbl align-top" />');
	*/
	}
	

	//unlike navButtons icons, action icons in rows seem to be hard-coded
	//you can change them like this in here if you want
	function updateActionIcons(table) {
		/**
		var replacement = 
		{
			'ui-ace-icon fa fa-pencil' : 'ace-icon fa fa-pencil blue',
			'ui-ace-icon fa fa-trash-o' : 'ace-icon fa fa-trash-o red',
			'ui-icon-disk' : 'ace-icon fa fa-check green',
			'ui-icon-cancel' : 'ace-icon fa fa-times red'
		};
		$(table).find('.ui-pg-div span.ui-icon').each(function(){
			var icon = $(this);
			var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
			if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
		})
		*/
	}
	
	//replace icons with FontAwesome icons like above
	function updatePagerIcons(table) {
		var replacement = 
		{
			'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
			'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
			'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
			'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
		};
		$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function(){
			var icon = $(this);
			var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
			
			if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
		})
	}

	function enableTooltips(table) {
		$('.navtable .ui-pg-button').tooltip({container:'body'});
		$(table).find('.ui-pg-div').tooltip({container:'body'});
	}

	function cLink(cellvalue, options, rowObject){
		if(cellvalue!==null&&cellvalue!==""){
		return "<a href='javascript:;' onclick='maintenancRecordDownload(\""+cellvalue+"\")'>下载</a>";
		}else{
			return '';
		}
		}
	function ajaxFileUpload(id){
		 $.ajaxFileUpload({
			 url: 'updateOperationRepairFile?id='+id,
	            secureuri: false,
	            fileElementId: 'filePath',
	            success: function (data, status) {
	            	jQuery("#grid-table").jqGrid('setGridParam', {
		                
		            }).trigger('reloadGrid');
	            }
		 });
		 
	};
	
	//var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

	$(document).one('ajaxloadstart.page', function(e) {
		$.jgrid.gridDestroy(grid_selector);
		$('.ui-jqdialog').remove();
	});
	function maintenancRecordDownload(path){
	window.open('operationRepairDownload?file='+encodeURIComponent(path));
	};
	
	function enabledrag(form){
		var dialog=form.closest('.ui-jqdialog');
		dialog.css('left',600).draggable();
	}
})(jQuery);

